package spring_root.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import spring_root.interceptor.loginInterceptor;

@Configuration
public class Config implements WebMvcConfigurer {

	/**
	 * /static/html/ - classpath:/static/css/ - classpath:/static/images/ -
	 * classpath:/static/js/ - /** - classpath:/static/ - classpath:/public/ -
	 * classpath:/resources/
	 */

	public void addResourceHandlers(ResourceHandlerRegistry registry) {

		registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
		registry.addResourceHandler("/html/**").addResourceLocations("classpath:/static/html/");
		registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
		registry.addResourceHandler("/images/**").addResourceLocations("classpath:/static/images/");
		
		registry.addResourceHandler("/static/js/**").addResourceLocations("classpath:/static/js/");
		registry.addResourceHandler("/static/html/**").addResourceLocations("classpath:/static/html/");
		registry.addResourceHandler("/static/css/**").addResourceLocations("classpath:/static/css/");
		registry.addResourceHandler("/static/images/**").addResourceLocations("classpath:/static/images/");

	}
	
	private String [] staticresourcespath = {"/index.html","/login","/","/js/**","/html/**","/css/**","/images/**","/static/js/**","/static/html/**","/static/css/**","/static/images/**"};
	
	
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(new loginInterceptor()).addPathPatterns("/**")
						.excludePathPatterns(staticresourcespath);
	}
}
